﻿Imports System
Imports System.Diagnostics

Namespace System.Workflow.Runtime
    Friend Class WorkflowTrace
        ' Methods
        Shared Sub New()
            WorkflowTrace.runtime.Switch = New SourceSwitch("System.Workflow.Runtime", SourceLevels.Off.ToString)
            WorkflowTrace.tracking = New TraceSource("System.Workflow.Runtime.Tracking")
            WorkflowTrace.tracking.Switch = New SourceSwitch("System.Workflow.Runtime.Tracking", SourceLevels.Off.ToString)
            WorkflowTrace.host = New TraceSource("System.Workflow.Runtime.Hosting")
            WorkflowTrace.host.Switch = New SourceSwitch("System.Workflow.Runtime.Hosting", SourceLevels.Off.ToString)
            Dim switch2 As New BooleanSwitch("System.Workflow LogToFile", "Log traces to file")
            If switch2.Enabled Then
                Dim listener As New TextWriterTraceListener("WorkflowTrace.log")
                Trace.Listeners.Add(listener)
                WorkflowTrace.runtime.Listeners.Add(listener)
                WorkflowTrace.host.Listeners.Add(listener)
            End If
            Dim switch3 As New BooleanSwitch("System.Workflow LogToTraceListeners", "Trace to listeners in Trace.Listeners", "0")
            If switch3.Enabled Then
                Dim listener2 As TraceListener
                For Each listener2 In Trace.Listeners
                    If Not TypeOf listener2 Is DefaultTraceListener Then
                        WorkflowTrace.runtime.Listeners.Add(listener2)
                        WorkflowTrace.tracking.Listeners.Add(listener2)
                        WorkflowTrace.host.Listeners.Add(listener2)
                    End If
                Next
            End If
        End Sub


        ' Properties
        Friend Shared ReadOnly Property Host As TraceSource
            Get
                Return WorkflowTrace.host
            End Get
        End Property

        Friend Shared ReadOnly Property Runtime As TraceSource
            Get
                Return WorkflowTrace.runtime
            End Get
        End Property

        Friend Shared ReadOnly Property Tracking As TraceSource
            Get
                Return WorkflowTrace.tracking
            End Get
        End Property


        ' Fields
        Private Shared host As TraceSource
        Private Shared runtime As TraceSource = New TraceSource("System.Workflow.Runtime")
        Private Shared tracking As TraceSource
    End Class
End Namespace

